package com.originskyseed.platform.count.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.originskyseed.platform.common.api.config.LoginConfig;
import com.originskyseed.platform.common.api.constant.RedisKeyConstans;
import com.originskyseed.platform.core.config.bean.ConfigManager;
import com.originskyseed.platform.core.redis.util.RedisUtil;
import com.originskyseed.platform.count.model.FinancialManage;
import com.originskyseed.platform.user.model.*;
import com.originskyseed.platform.user.model.*;
import com.originskyseed.platform.user.service.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.filter.helper.SingleSignOnTokenHelper;
import com.originskyseed.platform.count.i18n.CountResponseMsg;
import com.originskyseed.platform.count.service.IFinancialManageService;
import com.originskyseed.platform.count.vo.request.HomePageCountVO;
import com.originskyseed.platform.log.model.HomePageCache;
import com.originskyseed.platform.log.service.IHomePageCacheService;
import com.originskyseed.platform.user.service.IDeptService;
import com.originskyseed.platform.user.service.IParameterConfigureService;
import com.originskyseed.platform.user.service.IPlayerService;
import com.originskyseed.platform.user.service.ISalesmanLevelService;
import com.originskyseed.platform.user.service.ISalesmanRelateLevelService;
import com.originskyseed.platform.user.service.IUserInfoService;

/**
 * 推广类统计 业务员 Controller类
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/homePageSalesmanCount")
@BaseLocaleResource(localeFileName = "i18n_count")
public class HomePageSalesmanCountController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(HomePageSalesmanCountController.class);

	@DubboReference
	private IDeptService deptService;

	@DubboReference
	private IUserInfoService userInfoService;

	@DubboReference
	private IPlayerService playerService;

	@DubboReference
	private ISalesmanLevelService salesmanLevelaService;

	@DubboReference
	private ISalesmanRelateLevelService salesmanRelateLevelService;

	@DubboReference
	private IFinancialManageService financialManageService;

	@DubboReference
	private IParameterConfigureService parameterConfigureService;

	@DubboReference
	private IHomePageCacheService homePageCacheService;

	@DubboReference
	private ILevelSystemService levelSystemService;

	/**
	 * 查询所属公会
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectSalesmanHomePage.json")
	public BaseResponseBody selectSalesmanHomePage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Map<String, Object> map = new HashMap<>();
			String deptName = null;
			String levelName = null;
			String nexLevelName = null;
			BigDecimal maxValue = null;
			BigDecimal value = null;
			String levelSystemFilePath=null;
			String levelSystemFileName=null;

			// 点亮勋章，未点亮勋章
			List<String> lightUpMedal = new ArrayList<>();
			List<String> notLitMedal = new ArrayList<>();

			// 获取用户id
			String userId = selectUserId(request);

			UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
			if (userInfo != null) {
				String levelId = userInfo.getSalesmanLevelId();
				String account = userInfo.getAccount();
				// 获取工会
				Dept dept = this.deptService.selectByPrimaryKey(userInfo.getDeptId());
				if (dept != null) {
					deptName = selectLabourUnionId(dept.getCode());
				}

				// 获取等级
				if (StringUtils.isNotBlank(levelId)) {
					SalesmanLevel salesmanLevela = this.salesmanLevelaService.selectByPrimaryKey(levelId);
					if (salesmanLevela != null) {
						levelName = salesmanLevela.getLevelName();
						String systemId=salesmanLevela.getSystemId();
						LevelSystem levelSystem=this.levelSystemService.selectByPrimaryKey(systemId);
						if(levelSystem!=null)
						{
							levelSystemFilePath=levelSystem.getFilePath();
							levelSystemFileName=levelSystem.getFileName();
						}
						SalesmanLevel nextLevel = this.salesmanLevelaService.selectNexLevel(salesmanLevela.getEmpiricValueMax());
						if (nextLevel != null) {
							nexLevelName = nextLevel.getLevelName();
							maxValue = nextLevel.getEmpiricValueMin();
						}
					}
					SalesmanRelateLevel salesmanRelateLevel = this.salesmanRelateLevelService.selectByAccount(account);
					if (salesmanRelateLevel != null) {
						value = salesmanRelateLevel.getEmpiricValue();
					}
					// 判断有没有获得该勋章
					List<SalesmanLevel> salesmanLevelaList = this.salesmanLevelaService.selectList(new SalesmanLevel());
					if (value != null) {
						for (SalesmanLevel salesmanLevela1 : salesmanLevelaList) {
							if (value.compareTo(salesmanLevela1.getEmpiricValueMin()) >= 0) {
								lightUpMedal.add(salesmanLevela1.getMedalPic());
							} else {
								notLitMedal.add(salesmanLevela1.getMedalPic());
							}
						}
					}
				}
			}

			map.put("deptName", deptName);
			map.put("levelName", levelName);
			map.put("levelSystemFilePath", levelSystemFilePath);
			map.put("levelSystemFileName", levelSystemFileName);
			map.put("nexLevelName", nexLevelName);
			map.put("maxValue", maxValue);
			map.put("value", value);
			map.put("lightUpMedalList", lightUpMedal);
			map.put("notLitMedalList", notLitMedal);

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询我的任务
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMyMission.json")
	public BaseResponseBody selectMyMission(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Map<String, Object> map = new HashMap<>();

			// 获取用户id
			String userId = selectUserId(request);

			if (StringUtils.isNotBlank(userId)) {
				map = this.playerService.selectMyMission(userId);

				Map<String, Object> query = new HashMap<>();
				query.put("userId", userId);
				query.put("type", 1);
				List<String> promotionTaskList = this.playerService.selectPromotionTaskMaintenanceTask(query);
				query.put("type", 2);
				List<String> maintenanceTaskList = this.playerService.selectPromotionTaskMaintenanceTask(query);
				map.put("promotionTaskList", promotionTaskList);
				map.put("maintenanceTaskList", maintenanceTaskList);
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询我的KPI
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMyKPI.json")
	public BaseResponseBody selectMyKPI(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型
			Integer type = this.getParameterInteger("type", null);
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIWEEK");
			} else if(type == 2 ){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIMONTH");
			}else if(type == 3 ) {
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIQUARTER");
			}else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIYEAR");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				BigDecimal target = null;
				BigDecimal complete = null;
				// 获取业务员id
				String otherAccount = selectOtherAccount(request);
				// 获取用户id
				String userId = selectUserId(request);
				if (StringUtils.isNotBlank(userId)) {
					FinancialManage financialManage = new FinancialManage();
					financialManage.setObjId(userId);
					financialManage.setType(2);
					financialManage.setStartTime(getMonthFirstDay());
					List<FinancialManage> financialManageList = this.financialManageService.selectList(financialManage);
					if (financialManageList.size() > 0) {
						target = financialManageList.get(0).getAmount();
					}
					if (target != null) {
						if (type == 0) {
							target = target.divide(new BigDecimal(30), BigDecimal.ROUND_HALF_UP, 2);
						} else if (type == 1) {
							target = target.divide(new BigDecimal(4), BigDecimal.ROUND_HALF_UP, 2);
						} else if (type == 3) {
							target = target.multiply(new BigDecimal(4));
						} else if (type == 4) {
							target = target.multiply(new BigDecimal(12));
						}
					}
					List<String> userList = new ArrayList<>();
					userList.add(otherAccount);
					complete = this.playerService.selectTiredAndFullCount(userList, type, 0);
				}
				map.put("target", target);
				map.put("complete", complete);


				// 存进redis中
				if(type==0){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIDAY",map,getCacheInvalidTime());
				} else if (type==1){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIWEEK",map,getCacheInvalidTime());
				} else if(type == 2 ){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIMONTH",map,getCacheInvalidTime());
				}else if(type == 3 ) {
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIQUARTER",map,getCacheInvalidTime());
				}else{
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIYEAR",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询工会用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectUnionUsers.json")
	public BaseResponseBody selectUnionUsers(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map  = (Map<String, Object>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUnionUsers");

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					// 查询注册数，有效注册数
					map = this.playerService.selectSalesmanPlayerNumber(otherAccount);
					// 查询累充额度
					List<String> userList = new ArrayList<>();
					userList.add(otherAccount);
					BigDecimal complete = this.playerService.selectTiredAndFullCount(userList, 0, 0);
					map.put("complete", complete);

					// 存进redis里面
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUnionUsers",map,getCacheInvalidTime());
				}
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询今日业绩
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTodayAchievement.json")
	public BaseResponseBody selectTodayAchievement(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map  = (Map<String, Object>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTodayAchievement");

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					// 今日日期
					String today = getToday();
					// 昨天日期
					String yesterday = getYesterday();
					// 今日累充总额，昨日累充总额
					BigDecimal todayAmount = this.playerService.selectTiredAndFullCount(otherAccount, today, today);
					BigDecimal yesterdayAmount = this.playerService.selectTiredAndFullCount(otherAccount, yesterday, yesterday);
					map.put("todayProfit", todayAmount.multiply(new BigDecimal("0.3")));
					map.put("yesterdayProfit", yesterdayAmount.multiply(new BigDecimal("0.3")));

					// 存进redis里面
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTodayAchievement",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询季度奖金
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectQuarterlyBonus.json")
	public BaseResponseBody selectQuarterlyBonus(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map  = (Map<String, Object>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectQuarterlyBonus");

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					int quart = getQuarter();
					// 季度开始时间
					String quarterStartTime = getCurrentQuarterStartTime();
					// 季度结束时间
					String quarterEndTime = getCurrentQuarterEndTime();
					// 上季度开始时间
					String lastQuarterStartTime = getLastQuarterStartTime();
					// 上季度结束时间
					String lastQuarterEndTime = getLastQuarterEndTime();

					// 当前季度累充总额，上季度累充总额
					BigDecimal quarterAmount = this.playerService.selectTiredAndFullCount(otherAccount, quarterStartTime, quarterEndTime);
					BigDecimal lastQuarterAmount = this.playerService.selectTiredAndFullCount(otherAccount, lastQuarterStartTime, lastQuarterEndTime);

					BigDecimal quarterRatio = BigDecimal.ZERO;
					BigDecimal lastQuarterRatio = BigDecimal.ZERO;
					List<ParameterConfigure> parameterConfigureList = this.parameterConfigureService.selectByParentCode("QUARTERLY_BONUS_PROPORTION");
					for (ParameterConfigure parameterConfigure : parameterConfigureList) {
						if (parameterConfigure.getCode().equals(quart + "")) {
							quarterRatio = new BigDecimal(parameterConfigure.getValue());
						}
						int lastQuart = quart - 1 == 0 ? 4 : quart - 1;
						if (parameterConfigure.getCode().equals(lastQuart + "")) {
							lastQuarterRatio = new BigDecimal(parameterConfigure.getValue());
						}
					}

					map.put("quarterBonus", quarterAmount.multiply(quarterRatio));
					map.put("lastQuarterBonus", lastQuarterAmount.multiply(lastQuarterRatio));

					Date date = sdf.parse(quarterEndTime);
					long diff = date.getTime() - new Date().getTime();
					long days = diff / (1000 * 60 * 60 * 24);
					map.put("days", days);

					// 存进redis里面
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectQuarterlyBonus",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询年度奖金
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectYearBonus.json")
	public BaseResponseBody selectYearBonus(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map  = (Map<String, Object>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectYearBonus");

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					// 年开始时间
					String yearStartTime = getCurrentYearStartTime();
					// 年结束时间
					String yearEndTime = getCurrentYearEndTime();

					// 年累充总额，去年累充总额
					BigDecimal yearAmount = this.playerService.selectTiredAndFullCount(otherAccount, yearStartTime, yearEndTime);

					BigDecimal ratio = BigDecimal.ZERO;
					List<ParameterConfigure> parameterConfigureList = this.parameterConfigureService.selectByParentCode("YEAR_BONUS_PROPORTION");
					for (ParameterConfigure parameterConfigure : parameterConfigureList) {
						ratio = new BigDecimal(parameterConfigure.getValue());
					}

					map.put("yearBonus", yearAmount.multiply(ratio));
					long days = 0;
					if (yearEndTime != null && StringUtils.isNotEmpty(yearEndTime)) {
						Date date = sdf.parse(yearEndTime);
						long diff = date.getTime() - new Date().getTime();
						days = diff / (1000 * 60 * 60 * 24);
					}
					map.put("days", days);

					// 存进redis里面
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectYearBonus",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质用户数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUsersNumber.json")
	public BaseResponseBody selectHighQualityUsersNumber(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Integer count  = (Integer) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersNumber");

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(count==null){
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					count = this.playerService.selectHighQualityUsersNumber(otherAccount);
					// 存进redis里面
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersNumber",count,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), count);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询评级接口
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectGrade.json")
	public BaseResponseBody selectGrade(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Integer grade = null;

			// 获取用户id
			String userId = selectUserId(request);
			// 获取业务员id
			String otherAccount = selectOtherAccount(request);
			if (StringUtils.isNotBlank(otherAccount)) {
				int count = this.playerService.selectTodayRegisterNumber(otherAccount);

				Map<String, Object> map = this.playerService.selectTaskNumber(userId);
				BigDecimal total = new BigDecimal((String) map.get("total"));
				BigDecimal completeTotal = new BigDecimal((String) map.get("completeTotal"));

				BigDecimal ratio = total.divide(completeTotal, 3);
				BigDecimal compare = new BigDecimal(0.5);

				if (count >= 10 && ratio.compareTo(compare) >= 0) {
					grade = 0;
				} else if (count >= 5 && ratio.compareTo(compare) >= 0) {
					grade = 1;
				} else {
					grade = 2;
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), grade);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询用户充值金额统计图
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectUserRechargeStatistics.json")
	public BaseResponseBody selectUserRechargeStatistics(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型 0日，1周，2月，3季，4年
			Integer type = this.getParameterInteger("type", null);
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String userId = selectOtherAccount(request);
				if (StringUtils.isNotBlank(userId)) {
					List<String> userList = new ArrayList<>();
					userList.add(userId);
					map = this.playerService.selectUserRechargeStatistics(type, userList, 1);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectUserRechargeStatisticsMONTH",map,getCacheInvalidTime());
					}
				}
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新增注册用户统计
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectNewRegisteredUsers.json")
	public BaseResponseBody selectNewRegisteredUsers(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型 0日，1周，2月
			Integer type = this.getParameterInteger("type", null);
			// 业务员id
			String deptId = this.getParameterString("deptId", null);

			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String userId = selectOtherAccount(request);
				if (StringUtils.isNotBlank(userId)) {
					List<String> userList = new ArrayList<>();
					userList.add(userId);
					map = this.playerService.selectNewRegisteredUsers(userList, type);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewRegisteredUsersMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 分页查询潜力用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectPotentialUsersByPage.json")
	public BaseResponseBody selectPotentialUsersByPage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			HomePageCountVO requestVO = this.getParameterBean(HomePageCountVO.class);

			// 获取业务员id
			String userId = selectOtherAccount(request);
			// 分页查询
			BasePage<Map<String, Object>> page = new BasePage<Map<String, Object>>(requestVO.getPageNo(), requestVO.getPageSize());
			if (StringUtils.isNotBlank(userId)) {
				List<String> userList = new ArrayList<>();
				userList.add(userId);
				requestVO.setList(userList);
				page = this.playerService.selectPotentialUsersByPage(requestVO.toMap(), page);
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUsers.json")
	public BaseResponseBody selectHighQualityUsers(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型 0日，1周，2月
			Integer type = this.getParameterInteger("type", null);
			// 业务员id
			String deptId = this.getParameterString("deptId", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String userId = selectOtherAccount(request);
				if (StringUtils.isNotBlank(userId)) {
					List<String> userList = new ArrayList<>();
					userList.add(userId);
					map = this.playerService.selectHighQualityUsers(type,userList, 0);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsersMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 分页查询优质用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUsersByPage.json")
	public BaseResponseBody selectHighQualityUsersByPage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			HomePageCountVO requestVO = this.getParameterBean(HomePageCountVO.class);

			// 获取业务员id
			String userId = selectOtherAccount(request);

			// 分页查询
			BasePage<Map<String, Object>> page = new BasePage<Map<String, Object>>(requestVO.getPageNo(), requestVO.getPageSize());
			if (StringUtils.isNotBlank(userId)) {
				List<String> userList = new ArrayList<>();
				userList.add(userId);
				requestVO.setList(userList);
				page = this.playerService.selectHighQualityUsersByPage(requestVO.toMap(), page);
			}
			for (Map<String, Object> map : page.getResults()) {
				String belongBusinessId = (String) map.get("userId");
				UserInfo userInfo1 = this.userInfoService.selectByOtherAccount(belongBusinessId);
				if (userInfo1 != null) {
					map.put("account", userInfo1.getAccount());
					map.put("userId", userInfo1.getId());
					map.put("name", userInfo1.getName());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 分页查询私域流量池用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectFlowPoolUsersByPage.json")
	public BaseResponseBody selectFlowPoolUsersByPage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 请求对象
			HomePageCountVO requestVO = this.getParameterBean(HomePageCountVO.class);

			// 获取业务员id
			String userId = selectOtherAccount(request);
			// 分页查询
			BasePage<Map<String, Object>> page = new BasePage<Map<String, Object>>(requestVO.getPageNo(), requestVO.getPageSize());
			if (StringUtils.isNotBlank(userId)) {
				List<String> userList = new ArrayList<>();
				userList.add(userId);
				requestVO.setList(userList);
				page = this.playerService.selectFlowPoolUsersByPage(requestVO.toMap(), page);
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询业务员排行榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectSalesmanRanking.json")
	public BaseResponseBody selectSalesmanRanking(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Map<String, Object> resultMap = new HashMap<>();
			List<Map<String, Object>> resultList = new ArrayList<>();

			// 用户id
			String userId = selectUserId(request);
			if (StringUtils.isNotBlank(userId)) {
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
				List<String> list = new ArrayList<>();
				list.add(userInfo.getDeptId());
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(list);
				Map<String, Object> query = new HashMap<>();
				query.put("list", userList);
				resultList = this.playerService.selectSalesmanRanking(query);
				for (Map<String, Object> map : resultList) {
					String depId = (String) map.get("deptId");
					String deptName = selectLabourUnionNameById(depId);
					map.put("deptName", deptName);
				}
				resultMap.put("list", resultList);

				int rank = this.playerService.selectRankingByCount(userId, userList);
				resultMap.put("rank", rank);
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询公会名称
	 * 
	 * @param code
	 * @throws Exception
	 */
	private String selectLabourUnionId(String code) throws Exception {
		Dept dept = this.deptService.selectByCode(code);
		if (dept != null && dept.getType() != null) {
			if (dept.getType() == 1) {
				return dept.getName();
			} else {
				return selectLabourUnionId(dept.getParentCode());
			}
		} else {
			return null;
		}
	}

	/**
	 * 获取用户id
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	private String selectUserId(HttpServletRequest request) throws Exception {
		// 业务员id
		String userId = this.getParameterString("deptId", null);
		if (StringUtils.isBlank(userId)) {
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			userId = userInfo.getId();
		}
		return userId;
	}

	/**
	 * 获取业务员id
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	private String selectOtherAccount(HttpServletRequest request) throws Exception {
		String otherAccount = "";
		// 业务员id
		String userId = this.getParameterString("deptId", null);
		if (StringUtils.isBlank(userId)) {
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			if (userInfo != null) {
				otherAccount = userInfo.getOtherAccount();
			}
		} else {
			UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
			if (userInfo != null) {
				otherAccount = userInfo.getOtherAccount();
			}
		}
		return otherAccount;
	}

	/**
	 * 查询公会名称
	 * 
	 * @param id
	 * @throws Exception
	 */
	private String selectLabourUnionNameById(String id) throws Exception {
		Dept dept = this.deptService.selectByPrimaryKey(id);
		if (dept != null) {
			if (dept.getType() == 1) {
				return dept.getName();
			} else {
				Dept parentDept = this.deptService.selectByCode(dept.getParentCode());
				if (parentDept != null) {
					return selectLabourUnionId(parentDept.getId());
				} else {
					return null;
				}
			}
		} else {
			return null;
		}
	}


	// 日期格式化
	private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * 获得本周的第一天，周一
	 *
	 * @return
	 */
	public String getToday() {
		Calendar c = Calendar.getInstance();
		return sdf.format(c.getTime());
	}

	/**
	 * 获得昨天的日期
	 *
	 * @return
	 */
	public String getYesterday() {
		Calendar c = Calendar.getInstance();
		try {
			c.add(Calendar.DATE, -1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 获取季度
	 *
	 * @return
	 */
	public Integer getQuarter() {
		Calendar c = Calendar.getInstance();
		int quarter;
		int m = c.get(c.MONTH);
		if (m >= 1 && m <= 3) {
			quarter = 1;
		} else if (m >= 4 && m <= 6) {
			quarter = 2;
		} else if (m >= 7 && m <= 9) {
			quarter = 3;
		} else {
			quarter = 4;
		}
		return quarter;
	}

	/**
	 * 当前季度的开始时间
	 *
	 * @return
	 */
	public String getCurrentQuarterStartTime() {
		Calendar c = Calendar.getInstance();
		int currentMonth = c.get(Calendar.MONTH) + 1;
		try {
			if (currentMonth >= 1 && currentMonth <= 3)
				c.set(Calendar.MONTH, 0);
			else if (currentMonth >= 4 && currentMonth <= 6)
				c.set(Calendar.MONTH, 3);
			else if (currentMonth >= 7 && currentMonth <= 9)
				c.set(Calendar.MONTH, 4);
			else if (currentMonth >= 10 && currentMonth <= 12)
				c.set(Calendar.MONTH, 9);
			c.set(Calendar.DATE, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 当前季度的结束时间
	 *
	 * @return
	 */
	public String getCurrentQuarterEndTime() {
		Calendar c = Calendar.getInstance();
		int currentMonth = c.get(Calendar.MONTH) + 1;
		try {
			if (currentMonth >= 1 && currentMonth <= 3) {
				c.set(Calendar.MONTH, 2);
				c.set(Calendar.DATE, 31);
			} else if (currentMonth >= 4 && currentMonth <= 6) {
				c.set(Calendar.MONTH, 5);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 7 && currentMonth <= 9) {
				c.set(Calendar.MONTH, 8);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 10 && currentMonth <= 12) {
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 上个季度的开始时间
	 *
	 * @return
	 */
	public String getLastQuarterStartTime() {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, -4);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		try {
			if (currentMonth >= 1 && currentMonth <= 3)
				c.set(Calendar.MONTH, 0);
			else if (currentMonth >= 4 && currentMonth <= 6)
				c.set(Calendar.MONTH, 3);
			else if (currentMonth >= 7 && currentMonth <= 9)
				c.set(Calendar.MONTH, 4);
			else if (currentMonth >= 10 && currentMonth <= 12)
				c.set(Calendar.MONTH, 9);
			c.set(Calendar.DATE, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 上个季度的结束时间
	 *
	 * @return
	 */
	public String getLastQuarterEndTime() {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, -4);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		try {
			if (currentMonth >= 1 && currentMonth <= 3) {
				c.set(Calendar.MONTH, 2);
				c.set(Calendar.DATE, 31);
			} else if (currentMonth >= 4 && currentMonth <= 6) {
				c.set(Calendar.MONTH, 5);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 7 && currentMonth <= 9) {
				c.set(Calendar.MONTH, 8);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 10 && currentMonth <= 12) {
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 当前年的开始时间
	 *
	 * @return
	 */
	public String getCurrentYearStartTime() {
		Calendar c = Calendar.getInstance();
		try {
			c.set(Calendar.MONTH, 0);
			c.set(Calendar.DATE, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 当前年的结束时间
	 *
	 * @return
	 */
	public String getCurrentYearEndTime() {
		Calendar c = Calendar.getInstance();
		try {
			c.set(Calendar.MONTH, 11);
			c.set(Calendar.DATE, 31);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 去年的开始时间
	 *
	 * @return
	 */
	public String getLastYearStartTime() {
		Calendar c = Calendar.getInstance();
		try {
			c.add(Calendar.YEAR, -1);
			c.set(Calendar.MONTH, 0);
			c.set(Calendar.DATE, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 去年的结束时间
	 *
	 * @return
	 */
	public String getLastYearEndTime() {
		Calendar c = Calendar.getInstance();
		try {
			c.add(Calendar.YEAR, -1);
			c.set(Calendar.MONTH, 11);
			c.set(Calendar.DATE, 31);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}

	/**
	 * 查询本月第一天
	 *
	 * @return
	 * @throws Exception
	 */
	private Date getMonthFirstDay() throws Exception {
		Calendar c = Calendar.getInstance();
		try {
			c.set(Calendar.DATE, 1);
			c.set(Calendar.HOUR_OF_DAY, 0);
			c.set(Calendar.MINUTE, 0);
			c.set(Calendar.SECOND, 0);
			c.set(Calendar.MILLISECOND, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c.getTime();
	}

	/**
	 * 获取失效时间
	 * @return
	 */
	private long getCacheInvalidTime(){
		LoginConfig loginConfig = ConfigManager.getInstance().parseObject(LoginConfig.class);
		long timeOut = 7200000;
		if(loginConfig!=null && loginConfig.getCacheInvalidTime()!=null){
			timeOut = loginConfig.getCacheInvalidTime()*60*1000;
		}
		return timeOut;
	}
}